package com.ybfenpan.controller.admin.center;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ybfenpan.controller.core.BaseController;
import com.ybfenpan.model.Member;
import com.ybfenpan.model.Notice;
import com.ybfenpan.service.MemberService;
import com.ybfenpan.utils.MapUtil;

/**
 * Created by Administrator on 2016/3/25.
 */
@Controller
public class CentetShowController extends BaseController {

	@Resource
	private MemberService memberService;

	@RequestMapping("admin/center/centerShow.shtml")
	public String show(HttpServletRequest request) throws Exception {
		Map formMap = getParameterMap(request);
		int id = MapUtil.getIntValue(formMap, "id");
		if (0 < id) {
			Member center = memberService.getByKey(id);

			request.setAttribute("center", center);
		}
		return "admin/center/centerShow";

	}

	@RequestMapping("admin/center/centerUpdate.shtml")
	public String update(HttpServletRequest request, ModelMap model) throws Exception {
		Map formMap = getParameterMap(request);
		int id = MapUtil.getIntValue(formMap, "id");

		if (0 < id) {
			Map map2 = new HashMap();
			map2.put("id", id);
			map2.put("centerTitle", MapUtil.getString(formMap, "centerTitle"));
			map2.put("centerAdds", MapUtil.getString(formMap, "centerAdds"));

			// notice= noticeService.getByKey(id);
			// notice.setTitle(MapUtil.getString(formMap,"title"));
			// notice.setContent(MapUtil.getString(formMap,"content"));
			memberService.update(map2);

			setMessage(model, "更新成功！");
			Boolean result = true;
			request.setAttribute("result", result);
			Member center = memberService.getByKey(id);
			request.setAttribute("center", center);

		}
		return "admin/center/centerShow";
	}

}
